﻿@using Apps.Web.Core;
@using Apps.Web;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@using Wantn.FIS.Enum
@{
    ViewBag.Title = "化验结果审批";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<div class="mvctool bgb">
    <select class="easyui-combobox" name="BATCH_TYPE" id="BATCH_TYPE" style="width:120px;">
        <option value="">=== 全部类别 ===</option>
        <option value="入厂煤">入厂煤</option>
        <option value="自采煤">自采煤</option>
    </select>
    <input id="txtTestCode" class="condition-testcode" placeholder="化验号" type="text" />
    <input id="batchCode" class="condition-testcode" placeholder="批次号" type="text" />
    <select name="MATERIEL_ID" id="MATERIEL_ID" style="width:120px;"></select>
    <select class="easyui-combobox" name="TYPE_ID" id="TYPE_ID" style="width:120px;"></select>
    <input id="txtStartDate" placeholder="审批时间起" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', maxDate: '#F{$dp.$D(\'txtEndDate\')}' })" class="condition-date" type="text" />
    <input id="txtEndDate" placeholder="审批时间止" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', minDate: '#F{$dp.$D(\'txtStartDate\')}' })" class="condition-date" type="text" />
    @Html.DropDownList("queryState", EnumMvcHelper.GetMVCSelectList<ApprovalStatus>("审批状态"), new { @style = "width:100px;" })
    @Html.ToolButton("btnQueryParent", "fa fa-search", Resource.Query, ref perm, "Query", true)
    @Html.ToolButton("btnCheck", "fa fa-check", Resource.Check, ref perm, "Check", true)
    @Html.ToolButton("btnBatchCheck", "fa fa-check", "批量审批通过", ref perm, "Check", true)
    @Html.ToolButton("btnDetails", "fa fa-list", Resource.Details, ref perm, "Details", true)
    @*@Html.ToolButton("btnFiles", "fa fa-list", "岩相附件", ref perm, "YANXFILES", true)*@
    @Html.ToolButton("btnRelated", "fa fa-check", "小焦炉煤关联入厂", ref perm, "RELATED", true)

</div>
<table style="width:100%" class="formtable">
    <tbody>
        <tr>
            <td>
                <div class="hr"></div>
                <div title="流程审批" class="easyui-panel" style="padding:2px;width:100%">
                    <table id="ListParent" style="width:100%"></table>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="hr"></div>
                <div title="流程明细" class="easyui-panel" style="padding:2px;width:100%">
                    <table id="flowsteplist" style="width:100%"></table>
                </div>
            </td>
        </tr>
    </tbody>
</table>

@Html.Partial("~/Views/Shared/_Partial_AutoGrid.cshtml")

<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>

<script type="text/javascript">
    $(function () {

        $.ajax({
            url: '../../RC/SAMPLING/GetTranSuppList?type=4',
            type: 'post',
            dataType: 'json',
            success: function (result) {
                $('#TYPE_ID').combobox({
                    data: result,
                    valueField: 'Value',
                    textField: 'Text',
                    onLoadSuccess: function () {

                    }
                });
            },
        });

        GetTranSuppList(2, "@ViewBag.MATERIEL_ID");
        function FlowSTEPNOFormatter(value) {
            var stepname = "";
            if (value == 0) {
                stepname = "起草";
            }
            else {
                stepname = "第" + value + "步";
            }
            return stepname;
        }

        $('#flowsteplist').datagrid({
            url: '/Flow/Form/GetFlowStepInfoList?id=@ViewBag.ID',
            toolbar: '#DetailListTools',
            //width: SetGridWidthSub(40),
            methord: 'post',
            height: 200,
            fitColumns: true,
            sortName: 'TASKFINISHDATE',
            sortOrder: 'asc',
            idField: 'ID',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            columns: [[
               { field: 'STEPNO', title: '序号', width: 40, sortable: true, formatter: function (value, row) { return FlowSTEPNOFormatter(value) } },
                    { field: 'TITLE', title: '流程名称', width: 100, sortable: true },
                    { field: 'STEPNAME', title: '环节名称', width: 120, sortable: true },
                    { field: 'FORMLEVEL', title: '紧急程度', width: 80, sortable: true, hidden: true },
                    { field: 'CREATETIME', title: '流程开始时间', width: 80, sortable: true, hidden: true },
                    { field: 'TIMEOUT', title: '流程结束时间', width: 80, sortable: true, hidden: true },
                    { field: 'STARTUSERNAME', title: '起草人', width: 80, sortable: true, hidden: true },
                    { field: 'STEPSTATE', title: '环节状态', width: 50, sortable: true },
                    { field: 'TASKFINISHDATE', title: '下达时间', width: 90, sortable: true },
                    { field: 'USERNAME', title: '作业员', width: 60, sortable: true },
                    { field: 'CHECKTYPE', title: '处理方式', width: 50, sortable: true },
                    { field: 'REAMRK', title: '处理意见', width: 80, sortable: true },
                    { field: 'CHECKSTATE', title: '处理状态', width: 50, sortable: true },
                    //{ field: 'TASKFINISHDATE', title: '处理时间', width: 40, sortable: true, hidden: true ,formatter: function (value, row) { return "" }},
                    { field: 'STEPCHECKID', title: 'STEPCHECKID', width: 80, sortable: true, hidden: true },
                    { field: 'STATEFLAG', title: 'STATEFLAG', width: 80, sortable: true, hidden: true },
                    { field: 'STARTUSERID', title: 'STARTUSERID', width: 80, sortable: true, hidden: true },
                    { field: 'ID', title: 'ID', width: 80, sortable: true, hidden: true },
                    { field: 'FORMID', title: 'FORMID', width: 80, sortable: true, hidden: true },
                    { field: 'USERID', title: 'USERID', width: 80, sortable: true, hidden: true },
                    { field: 'ATTRZ', title: 'ATTRZ', width: 80, sortable: true, hidden: true }

            ]],
            onLoadSuccess: function (data) {
                var allRows = $('#flowsteplist').datagrid('getRows');
                if (allRows.length > 0) {
                    allRows.forEach(function (item) {
                        if (item.USERID == "@(ViewBag.UserID)" && (item.CHECKSTATE == "审批中" || item.CHECKSTATE == "待申请或终止" || item.CHECKSTATE == "待申请")) {
                            $("#btnCheck").show();
                            return;
                        }

                    });
                }
            }
        });

        $('#ListParent').datagrid({
            url: '@Url.Action("GetFlowList")',
            //width: SetGridWidthSub(40),
            methord: 'post',
            height: SetGridHeightSub(320),
            fitColumns: true,
            sortName: 'AUDIT_TIME',
            sortOrder: 'desc',
            idField: 'TEST_CODE',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            checkOnSelect: false,
            selectOnCheck: false,
            rownumbers: true,//行号
            onLoadSuccess: function (data) {
                //默认选中第一行
                var rows = $('#ListParent').datagrid('getRows');
                if (rows != null && rows.length > 0) {
                    currow = rows[0];
                    $('#ListParent').datagrid('selectRow', 0);
                    $("#btnCheck").hide();
                    $('#flowsteplist').datagrid("load", { id: currow.AUDIT_ID });
                }
            },
            columns: [[
                 { field: 'ck',title:'<div class="datagrid-header-check"><input type="checkbox"></div>', formatter: function (value,row) {
                      if (row.AUDIT_USER_ID != null && row.AUDIT_USER_ID.indexOf("@(ViewBag.UserID)") >= 0 && row.APPROVAL_STATUS == 2) {
                         return '<div style="" class="datagrid-cell-check"><input type="checkbox" name="ck" value=""></div>';
                     }
                     return ''; }
                 },
                { field: 'TEST_CODE', title: '化验编码', width: 120, sortable: true },
                { field: 'MATERIEL_NAME', title: '物料', width: 100, sortable: true },
                { field: 'BATCH_TYPE', title: '采样类型', width: 100, sortable: true },
                { field: 'TYPE_STR', title: '类型', width: 100, sortable: true },
                { field: 'MT', title: '全水分<br>Mt(%)', width: 80 },
                { field: 'MAD', title: '空气干燥基水分<br>Mad(%)', width: 80 },
                { field: 'AD', title: '干燥基灰分<br>Ad(%)', width: 80 },
                { field: 'VDAF', title: '干燥无灰基挥发分<br>Vdaf(%)', width: 80 },
                { field: 'STD', title: '干燥基硫<br>St,d(%)', width: 80 },
                { field: 'G', title: '粘结指数<br>G', width: 80 },
                { field: 'Y', title: '胶质最大角质层厚度<br>Y', width: 80 },
                { field: 'X', title: '胶质最大收缩度<br>X', width: 80 },
                { field: 'A', title: '奥亚最大收缩度<br>a', width: 80 },
                { field: 'B', title: '奥亚最大膨胀度<br>b', width: 80 },
                { field: 'QNETAR_KCAL', title: '收到基低位发热值<br>Qnet,ar/kal(Kcal/kg)', width: 80 },
                //新增字段 BEGIN
                { field: 'SMALL', title: '筛分粒度<3mm(%)', width: 80 },
                { field: 'MEDIUM', title: '筛分粒度3~10mm(%)', width: 80 },
                { field: 'LARGE', title: '筛分粒度>10mm(%)', width: 80 },
                { field: 'CRI', title: 'CRI(%)', width: 80 },
                { field: 'CSR', title: 'CSR(%)', width: 80 },
                { field: 'M40', title: 'M40(%)', width: 80 },
                { field: 'M10', title: 'M10(%)', width: 80 },
                { field: 'JTXXLARGE', title: '筛分粒度>80mm(%)', width: 80 },
                { field: 'JTXLARGE', title: '筛分粒度80~60mm%)', width: 80 },
                { field: 'JTLARGE', title: '筛分粒度60~40mm%)', width: 80 },
                { field: 'JTMEDIUM', title: '筛分粒度40-25mmmm(%)', width: 80 },
                { field: 'JTSMALL', title: '筛分粒度<25mm(%)', width: 80 },
                { field: 'YANX_VALUE', title: '岩相', width: 80 },
                //END
                { field: 'AUDIT_TIME', title: '申请时间', width: 160 },
                { field: 'AUDIT_USER_ID', hidden: true, title: '审批人', width: 160 },
                { field: 'APPROVAL_STATUS', title: '审批状态', width: 80, sortable: true, formatter: @Html.Raw(GridHelper.GridFormatterFunc<ApprovalStatus>("gConvertApprovalStatus")) },
                { field: 'TEMPLATE_ID', title: '', width: 80, sortable: true, hidden: true }
            ]], onClickRow: function (index, row) {
                if (row != null) {
                    currow = row;
                    $("#btnCheck").hide();
                    $('#flowsteplist').datagrid("load", { id: row.AUDIT_ID });
                }
            }
        });
    });

    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag) {
            $("#ListParent").datagrid('load');
            $("#ListParent").datagrid('clearChecked');

    }
        else
            $("#ListParent").datagrid('reload');
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
    $(function () {
        $("#btnCheck").click(function () {
            var checkData = $("#ListParent").datagrid("getChecked");
            if (checkData.length==0) {
                $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords');
            } else if (checkData.length > 1) {
                $.messageBox5s(Lang.Tip, '只能选中一条进行审批');
            }
            else {
                FlowCheck("化验结果", checkData[0].AUDIT_ID, checkData[0].TEMPLATE_ID, SetGridWidthSub(20), SetGridHeightSub(40));
            }
        });

        $("#btnBatchCheck").click(function () {
            var data = $("#ListParent").datagrid("getChecked");
            if (data != null && data.length > 0) {
                var auditids = ""
                $.each(data, function (i, row) {
                     if (row.AUDIT_USER_ID != null && row.AUDIT_USER_ID.indexOf("@(ViewBag.UserID)") >= 0 && row.APPROVAL_STATUS == 2) {
                        if (auditids == "") {
                            auditids = row.AUDIT_ID;
                        }
                        else {
                            auditids = auditids + "," + row.AUDIT_ID;
                        }
                    }
                });

                if (auditids == "")
                {
                    $.messageBox5s(Lang.Tip, '没有可审批记录');
                    return;
                }

                $.messager.confirm(index_lang_tip, '确定要批量审批通过？', function (r) {
                    if (r) {
                        $.ajax({
                            url: "@Url.Action("BatchCheck")",
                            type: "Post",
                            data:{auditids:auditids},
                            dataType: "json",
                            success: function (data) {
                                if (data.type == 1) {
                                    $("#ListParent").datagrid('load');
                                }
                                $.messageBox5s(Lang.Tip, data.message);
                            }
                        });
                    }
                });

            }
            else { $.messageBox5s(Lang.Tip, '没有可审批记录'); }
        });


        $("#btnDetails").click(function () {
            if (currow != null) {
                FlowDetail("化验结果", currow.AUDIT_ID, currow.TEMPLATE_ID, SetGridWidthSub(20), SetGridHeightSub(40));
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
        });

        $("#btnFiles").click(function () {
            if (currow != null) {
                var row = $('#ListParent').datagrid('getSelected');
                console.log(row,'rererer')
                if (row != null) {
                    $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='@Url.Action("Yanx")?id=" + row.BATCH_CODE + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '岩相分析附件', width:500, height: 300, iconCls: 'fa fa-pencil' }).window('open');
                } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }

            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
        });

        $("#btnRelated").click(function () {
             if (currow != null) {
                 var row = $('#ListParent').datagrid('getSelected');
                 console.log(row, 'rererer')
                 if (row != null) {
                     if (row.BATCH_TYPE != "自采煤") {
                         $.messageBox5s(Lang.Tip, '请选择小焦炉煤或者焦炭');
                         return;
                     }
                     if (row.TYPE_STR != "小焦炉煤" && row.TYPE_STR != "小焦炉焦炭") {
                         $.messageBox5s(Lang.Tip, '请选择小焦炉煤或者焦炭');
                         return;
                     }
                     $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='@Url.Action("Related")?textCode=" + row.TEST_CODE + "&Ieguid=" + GetGuid() + "'></iframe>");
                 $("#modalwindow").window({ title: '自采煤关联入厂', width:500, height: 300, iconCls: 'fa fa-pencil' }).window('open');
                 } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }

             } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
         });

        $("#btnQueryParent").click(function () {
            $("#ListParent").datagrid("load", {
                TestCode: $("#txtTestCode").val(),
                MaterielName: $("#MATERIEL_ID").combobox('getText').toString(),
                StartDate: $("#txtStartDate").val(),
                EndDate: $("#txtEndDate").val(),
                TypeStr: $("#TYPE_ID").combobox('getValues').toString(),
                BatchCode: $("#batchCode").val(),
                BatchType: $("#BATCH_TYPE").combobox('getValues').toString(),
                ApprovalStatus:  $("#queryState").val(),
            });
        });
    });
</script>
